package com.hq.es.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 在Spring容器中定义 RestClient 对象
 * @Author: keats_coder
 * @Date: 2019/8/9
 * @Version 1.0
 * */
@Configuration
public class ElasticsearchConfig {
    @Value("${hq.elasticsearch.ip}")
    private String ip;

    @Bean
    public RestHighLevelClient restHighLevelClient() {
        HttpHost[] httpHostArray = new HttpHost[]{
                new HttpHost(ip, 9200, "http")
        };
        return new RestHighLevelClient(RestClient.builder(httpHostArray));
    }


}
